//
//  CommonUtils.m
//  AssistantDriving
//
//  Created by dcr on 2017/1/10.
//  Copyright © 2017年 邓兆太. All rights reserved.
//

#import "CommonUtils.h"

@implementation CommonUtils

/**
 @method 从字符串中根据分割符<BR>分割字符串，
 @param str 要分割的字符串
 @result NSArray 分割后的字符串
 */
+ (NSArray *)getAnswerWithString:(NSString *)str{
    NSMutableArray *array = [[NSMutableArray alloc]init];
    NSArray *arr = [str componentsSeparatedByString:@"<BR>"];
    [array addObject:arr[0]];
    for(int i = 0;i < 4; i++){
        [array addObject:[arr[i+1] substringFromIndex:2]];
    }
    return array;
}

/**
 @method 得到指定字符串的区域大小
 @param str 要计算的字符串
 @param font 字体的大小
 @param width 限制字符串的显示宽度
 @result CGSize 计算后区域大小
 */
+ (CGSize)getSizeWithString:(NSString *)str withFont:(UIFont *)font withWidth:(CGFloat)width{
    NSStringDrawingOptions opts = NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading;
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    [style setLineBreakMode:NSLineBreakByCharWrapping];
    NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:style};
    return [str boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:opts attributes:dic context:nil].size;
}
@end
